package com.foton.logistic.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.foton.logistic.model.GPSEntity;
import com.foton.logistic.model.order.LocalOrderEntity;
import com.foton.logistic.model.order.OrderEntity;
import com.foton.logistic.model.order.OrderListResult;
import com.foton.logistic.model.user.UserModelEntity;
import com.foton.logistic.util.tool.JacksonUtil;
import com.foton.logistic.util.tool.LogUtil;
import com.foton.logistic.util.tool.StringUtil;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


public class SharedUtil {
    public final static String LOGIN = "LOGIN";
    public final static String CarType = "CarType";
    public final static String RegTel1 = "RegTel1";
    public final static String CarrierId1 = "CarrierId1";
    public final static String USER_ID = "USER_ID";
    public final static String USER_TOKEN = "USER_TOKEN";
    public final static String USER_TEL = "USER_TEL";
    public final static String CarrierId = "CarrierId";
    public final static String Name = "Name";
    public final static String Sf = "Sf";
    public final static String JsCard = "JsCard";
    public final static String Code = "Code";
    public final static String RegTel = "RegTel";
    public final static String Gender = "Gender";
    public final static String Password = "Password";
    //经纬度
    public final static String LOCATION = "LOCATION";
    public final static String LOCATION1 = "LOCATION1";
    public final static String LATITUDE = "LATITUDE";
    public final static String LONGITUDE = "LONGITUDE";
    public final static String WEATHER = "WEATHER";
    public final static String HELP = "HELP";
    public final static String IGNOREVERSION = "IGNOREVERSION";//忽略版本
    public final static String ADIMAGEPATH = "ADIMAGEPATH";
    public final static String CITY = "CITY";
    public final static String OUTSERVICEROAD = "OUTSERVICEROAD";
    public final static String ORDERTIMER = "ORDERTIMER";
    public final static String PUSHSET = "PUSHSET";
    public final static String MIUI = "MIUI";
    public final static String USER_INFO = "USER_INFO";
    public final static String RETRY_TIME = "RETRY_TIME";
    public final static String ORDER_LIST = "ORDER_LIST";
    public final static String LOCAL_ORDER = "LOCAL_ORDER";
    public final static String RECOVER_TIME ="RECOVER_TIME";
    public final static String FAIL_TIME ="FAIL_TIME";
    public final static String LAT = "LAT";
    /**
     * 保存是否是miui系统
     *
     * @param context
     * @param entity  用户信息实体类
     */
    public static void saveUserInfo(Context context, UserModelEntity entity) {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(
                    byteArrayOutputStream);
            objectOutputStream.writeObject(entity);
            String serStr = byteArrayOutputStream.toString("ISO-8859-1");
            serStr = java.net.URLEncoder.encode(serStr, "UTF-8");
            objectOutputStream.close();
            byteArrayOutputStream.close();

            LogUtil.d("serialize str =" + serStr);

            SharedPreferences sp = context.getSharedPreferences(USER_INFO, 0);
            SharedPreferences.Editor editor = sp.edit();
            editor.clear();
            editor.putString(USER_INFO, serStr);
            editor.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static UserModelEntity getUserInfo(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(USER_INFO, 0);
        String info = sp.getString(USER_INFO, "");

        UserModelEntity entity = null;

        try {
            String redStr = java.net.URLDecoder.decode(info, "UTF-8");
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
                    redStr.getBytes("ISO-8859-1"));
            ObjectInputStream objectInputStream = new ObjectInputStream(
                    byteArrayInputStream);
            entity = (UserModelEntity) objectInputStream.readObject();
            objectInputStream.close();
            byteArrayInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return entity;
    }

    /**
     * 保存用户id
     *
     * @param context
     * @param id      用户id
     */
    public static void saveUserId(Context context, String id) {
        SharedPreferences sp = context.getSharedPreferences(USER_ID, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(USER_ID, id);
        editor.commit();
    }

    public static String getUserId(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(USER_ID, 0);
        String id = sp.getString(USER_ID, "");
        return id;
    }

    /**
     * 保存用户token
     *
     * @param context
     * @param token   保存用户token
     */
    public static void saveToken(Context context, String token) {
        SharedPreferences sp = context.getSharedPreferences(USER_TOKEN, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(USER_TOKEN, token);
        editor.commit();
    }

    public static String getToken(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(USER_TOKEN, 0);
        String id = sp.getString(USER_TOKEN, "");
        return id;
    }
    /**
     * 保存注册tel
     *
     * @param context
     * @param tel     tel
     */
    public static void saveRegTel(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(RegTel, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(RegTel, tel);
        editor.commit();
    }

    public static String getRegTel(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(RegTel, 0);
        String str = sp.getString(RegTel, "");
        return str;
    }
    /**
     * 保存注册tel
     *
     * @param context
     * @param tel     tel
     */
    public static void saveRegTel1(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(RegTel1, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(RegTel1, tel);
        editor.commit();
    }

    public static String getRegTel1(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(RegTel1, 0);
        String str = sp.getString(RegTel1, "");
        return str;
    }
    /**
     * 保存验证Code
     *
     * @param context
     * @param tel     tel
     */
    public static void saveCode(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(Code, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(Code, tel);
        editor.commit();
    }

    public static String getCode(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(Code, 0);
        String str = sp.getString(Code, "");
        return str;
    }
    /**
     * 保存password
     *
     * @param context
     * @param tel     tel
     */
    public static void savePassword(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(Password, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(Password, tel);
        editor.commit();
    }

    public static String getPassword(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(Password, 0);
        String str = sp.getString(Password, "");
        return str;
    }
    /**
     * 保存性别
     *
     * @param context
     * @param tel     tel
     */
    public static void saveGender(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(Gender, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(Gender, tel);
        editor.commit();
    }

    public static String getGender(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(Gender, 0);
        String str = sp.getString(Gender, "");
        return str;
    }
    /**
     * 保存用户tel
     *
     * @param context
     * @param tel     tel
     */
    public static void saveTel(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(USER_TEL, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(USER_TEL, tel);
        editor.commit();
    }

    public static String getTel(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(USER_TEL, 0);
        String str = sp.getString(USER_TEL, "");
        return str;
    }
    /**
     * 保存CarrierId
     *
     * @param context
     * @param tel     tel
     */
    public static void saveCarrierId(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(CarrierId, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(CarrierId, tel);
        editor.commit();
    }

    public static String getCarrierId(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(CarrierId, 0);
        String str = sp.getString(CarrierId, "");
        return str;
    }
    /**
     * 保存Name
     *
     * @param context
     * @param tel     tel
     */
    public static void saveName(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(Name, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(Name, tel);
        editor.commit();
    }

    public static String getName(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(Name, 0);
        String str = sp.getString(Name, "");
        return str;
    }
    /**
     * 保存CarType
     *
     * @param context
     * @param tel     tel
     */
    public static void saveCarType(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(CarType, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(CarType, tel);
        editor.commit();
    }

    public static String getCarType(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(CarType, 0);
        String str = sp.getString(CarType, "");
        return str;
    }
    /**
     * 保存身份证
     *
     * @param context
     * @param tel     tel
     */
    public static void saveSf(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(Sf, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(Sf, tel);
        editor.commit();
    }

    public static String getSf(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(Sf, 0);
        String str = sp.getString(Sf, "");
        return str;
    }
    /**
     * 保存身份证
     *
     * @param context
     * @param
     */
    public static void saveCarrierId1(Context context, String CarrierId) {
        SharedPreferences sp = context.getSharedPreferences(CarrierId1, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(CarrierId1, CarrierId);
        editor.commit();
    }

    public static String getCarrierId1(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(CarrierId1, 0);
        String str = sp.getString(CarrierId1, "");
        return str;
    }
    /**
     * 保存用户tel
     *
     * @param context
     * @param tel     tel
     */
    public static void saveJsCard(Context context, String tel) {
        SharedPreferences sp = context.getSharedPreferences(JsCard, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(JsCard, tel);
        editor.commit();
    }

    public static String getJsCard(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(JsCard, 0);
        String str = sp.getString(JsCard, "");
        return str;
    }
    /**
     * 保存设备断开信息
     *
     * @param context
     * @param lat
     * @param lng
     */
    public static void saveLocation1(Context context, double lat, double lng,String
            address,String time) {
        SharedPreferences sp = context.getSharedPreferences(LOCATION1, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();

        GPSEntity gpsEntity = LocationUtil.gcj_To_Gps84(lat, lng);
        double wgLat = gpsEntity.getWgLat();
        double wgLon = gpsEntity.getWgLon();
        String strLat = String.valueOf(wgLat);
        String strLon = String.valueOf(wgLon);
        if (strLat.length()>13){
            strLat = strLat.substring(0,13);
        }
        if (strLon.length()>13){
            strLon = strLon.substring(0,13);
        }

        editor.putString("lat", strLat);
        editor.putString("lng", strLon);
        editor.putString("address", address);
        editor.putString("time", time);
        editor.commit();
    }
    /**
     * 获取纬度
     *
     * @param context
     * @return
     */
    public static String getLat1(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION1, 0);
        String lat = sp.getString("lat", "");
        if (StringUtil.isEmpty(lat)) {
            lat = "";
        }
        return lat;
    }

    /**
     * 获取经度
     *
     * @param context
     * @return
     */
    public static String getLng1(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION1, 0);
        String lng = sp.getString("lng", "");
        if (StringUtil.isEmpty(lng)) {
            lng = "";
        }
        return lng;
    }
    /**
     * 获取地址
     *
     * @param context
     * @return
     */
    public static String getAddress1(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION1, 0);
        String address = sp.getString("address", "");
        if (StringUtil.isEmpty(address)) {
            address = "";
        }
        return address;
    }
    public static String getTime1(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION1, 0);
        String time = sp.getString("time", "");
        if (StringUtil.isEmpty(time)) {
            time = "";
        }
        return time;
    }
    /**
     * 保存恢复时间
     *
     * @param context
     * @param time
     */
    public static void saveRoverTime(Context context,long time){
        SharedPreferences sp = context.getSharedPreferences(RECOVER_TIME, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putLong(RECOVER_TIME, time);
        editor.commit();
    }
    public static long getRoverTime(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(RECOVER_TIME, 0);
        Long time = sp.getLong(RECOVER_TIME, 0);
        return time;
    }
    /**
     * 保存断开时间
     *
     * @param context
     * @param time
     */
    public static void saveFailTime(Context context,long time){
        SharedPreferences sp = context.getSharedPreferences(FAIL_TIME, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putLong(FAIL_TIME, time);
        editor.commit();
    }
    public static long getFailTime(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(FAIL_TIME, 0);
        Long time = sp.getLong(FAIL_TIME, 0);
        return time;
    }
    /**
     * 保存地理位置信息
     *
     * @param context
     * @param lat
     * @param lng
     */
    public static void saveLocation(Context context, double lat, double lng, String city, String
            address, String coorType, String code) {
        SharedPreferences sp = context.getSharedPreferences(LOCATION, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();

        GPSEntity gpsEntity = LocationUtil.gcj_To_Gps84(lat, lng);
        double wgLat = gpsEntity.getWgLat();
        double wgLon = gpsEntity.getWgLon();
        String strLat = String.valueOf(wgLat);
        String strLon = String.valueOf(wgLon);
        if (strLat.length()>13){
            strLat = strLat.substring(0,13);
        }
        if (strLon.length()>13){
            strLon = strLon.substring(0,13);
        }

        editor.putString("lat", strLat);
        editor.putString("lng", strLon);
        editor.putString("city", city);
        editor.putString("address", address);
        editor.putString("coorType", coorType);
        editor.putString("code", code);
        editor.commit();
    }

    /**
     * 获取纬度
     *
     * @param context
     * @return
     */
    public static String getLat(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION, 0);
        String lat = sp.getString("lat", "0");
        if (StringUtil.isEmpty(lat)) {
            lat = "";
        }
        return lat;
    }

    /**
     * 获取经度
     *
     * @param context
     * @return
     */
    public static String getLng(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION, 0);
        String lng = sp.getString("lng", "0");
        if (StringUtil.isEmpty(lng)) {
            lng = "";
        }
        return lng;
    }

    /**
     * 获取城市
     *
     * @param context
     * @return
     */
    public static String getCity(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION, 0);
        String city = sp.getString("city", "");
        if (StringUtil.isEmpty(city)) {
            city = "";
        }
        return city;
    }

    public static String getCityCode(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION, 0);
        String code = sp.getString("code", "");
        if (StringUtil.isEmpty(code)) {
            code = "";
        }
        return code;
    }

    /**
     * 获取地址
     *
     * @param context
     * @return
     */
    public static String getAddress(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION, 0);
        String address = sp.getString("address", "");
        if (StringUtil.isEmpty(address)) {
            address = "";
        }
        return address;
    }

    /**
     * 获取坐标类型
     *
     * @param context
     * @return
     */
    public static String getCoorType(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOCATION, 0);
        String coorType = sp.getString("coorType", "");
        if (StringUtil.isEmpty(coorType)) {
            coorType = "";
        }
        return coorType;
    }

    /**
     * 保存帮助界面显示状态
     *
     * @param context
     * @param status  true表示需要显示
     */
    public static void saveHelpStatus(Context context, boolean status, int code) {
        SharedPreferences sp = context.getSharedPreferences(HELP, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putBoolean(HELP, status);
        editor.putInt("code", code);
        editor.commit();
    }

    public static boolean getHelpStatus(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(HELP, 0);
        boolean status = sp.getBoolean(HELP, true);
        return status;
    }

    public static int getHelpCode(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(HELP, 0);
        int code = sp.getInt("code", 1);
        return code;
    }

    /**
     * 保存忽略版本
     *
     * @param context
     * @param version 忽略版本
     */
    public static void saveIgnoreVersion(Context context, String version) {
        SharedPreferences sp = context.getSharedPreferences(IGNOREVERSION, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(IGNOREVERSION, version);
        editor.commit();
    }

    public static String getIgnoreVersion(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(IGNOREVERSION, 0);
        String id = sp.getString(IGNOREVERSION, "");
        return id;
    }

    /**
     * 设置页面引导已知道
     *
     * @param context
     * @param className
     * @param first
     */
    public static void saveFisrt(Context context, String className, boolean first) {
        SharedPreferences sp = context.getSharedPreferences(className, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putBoolean("first", first);
        editor.commit();
    }

    public static boolean getFirst(Context context, String className) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(className, 0);
        boolean bool = sp.getBoolean("first", false);
        return bool;
    }

    /**
     * 保存广告图片路径
     *
     * @param context
     * @param url
     */
    public static void saveAdImage(Context context, String url) {
        SharedPreferences sp = context.getSharedPreferences(ADIMAGEPATH, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(ADIMAGEPATH, url);
        editor.commit();
    }

    public static String getAdImage(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(ADIMAGEPATH, 0);
        String id = sp.getString(ADIMAGEPATH, "");
        return id;
    }

    public static void saveOutServiceRoadOrder(Context context, OrderEntity orderEntity) {
        String soeStr = JacksonUtil.getInstance().writeValueAsString(orderEntity);
        saveOutServiceRoadOrder(context, soeStr);
    }

    public static void saveOutServiceRoadOrder(Context context, String str) {
        SharedPreferences sp = context.getSharedPreferences(OUTSERVICEROAD, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString("str", str);
        editor.commit();
    }

    public static String getOutServiceRoadOrder(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(OUTSERVICEROAD, 0);
        String str = sp.getString("str", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    public static void saveOrderList(Context context, OrderListResult orderListResult) {
        String soeStr = JacksonUtil.getInstance().writeValueAsString(orderListResult);
        saveOrderList(context, soeStr);
    }

    public static OrderListResult getOrderListResult(Context context) {
        OrderListResult orderListResult = null;
        String str = getOrderList(context);
        if (!StringUtil.isEmpty(str)){
            orderListResult = JacksonUtil.getInstance().readValue(str,OrderListResult.class);
        }
        return orderListResult;
    }

    public static void saveOrderList(Context context, String str) {
        SharedPreferences sp = context.getSharedPreferences(ORDER_LIST, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString("str", str);
        editor.commit();
    }

    public static String getOrderList(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(ORDER_LIST, 0);
        String str = sp.getString("str", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    /**
     * 保存定时时间
     *
     * @param context
     * @param time   timer
     */
    public static void saveRetryTime(Context context,long time){
        SharedPreferences sp = context.getSharedPreferences(RETRY_TIME, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putLong(RETRY_TIME, time);
        editor.commit();
    }

   /* *//**
     * 获取重试时间
     *
     * @param context
     * @return 当上传轨迹从未失败时,默认每半个小时上传轨迹(上传逻辑),当上传轨迹失败时,重试时间加五分钟
     * @see
     */
    public static long getRetryTime(Context context){
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(RETRY_TIME, 0);
        Long time = sp.getLong(RETRY_TIME, BaseConstant.UPLOAD_TRACK_NORMAL);
        return time;
    }

    public static void saveLAT(Context context,Float time){
        SharedPreferences sp = context.getSharedPreferences(LAT, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putFloat(LAT, time);
        editor.commit();
    }



    public static Float getLAT(Context context){
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LAT, 0);
        Float time = sp.getFloat(RETRY_TIME, 0);
        return time;
    }

    /**
     * 保存定时时间
     *
     * @param context
     * @param timer   timer
     */
    public static void saveOrderTimer(Context context, long timer) {
        SharedPreferences sp = context.getSharedPreferences(ORDERTIMER, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putLong(ORDERTIMER, timer);
        editor.commit();
    }

    public static Long getOrderTimer(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(ORDERTIMER, 0);
        Long time = sp.getLong(ORDERTIMER, 0);
        return time;
    }

    /**
     * 保存是否已经设置推送
     *
     * @param context
     * @param str
     */
    public static void savePushSet(Context context, boolean str) {
        SharedPreferences sp = context.getSharedPreferences(PUSHSET, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putBoolean(PUSHSET, str);
        editor.commit();
    }

    public static boolean getPushSet(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(PUSHSET, 0);
        boolean bool = sp.getBoolean(PUSHSET, false);
        return bool;
    }
    /**
     * 保存是否登录
     *
     * @param context
     * @param str
     */
    public static void saveLogin(Context context, boolean str) {
        SharedPreferences sp = context.getSharedPreferences(LOGIN, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putBoolean(LOGIN, str);
        editor.commit();
    }

    public static boolean getLogin(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(LOGIN, 0);
        boolean bool = sp.getBoolean(LOGIN, true);
        return bool;
    }

    public static String getWeatherResult(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(WEATHER, 0);
        String str = sp.getString("result", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    public static String getChooseCity(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(CITY, 0);
        String str = sp.getString("name", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    public static String getChooseCode(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(CITY, 0);
        String str = sp.getString("code", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    public static String getFlagResult(Context context) {
        Context ctx = context;
        SharedPreferences sp = ctx.getSharedPreferences(WEATHER, 0);
        String str = sp.getString("flag", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    public static void saveWeatherResult(Context context, String flag, String result) {
        SharedPreferences sp = context.getSharedPreferences(WEATHER, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString("flag", flag);
        editor.putString("result", result);
        editor.commit();
    }

    public static void saveChooseCity(Context context, String name, String code) {
        SharedPreferences sp = context.getSharedPreferences(CITY, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString("name", name);
        editor.putString("code", code);
        editor.commit();
    }

    /**
     * 保存是否是miui系统
     *
     * @param context
     * @param isMIUI
     */
    public static void saveMIUI(Context context, boolean isMIUI, boolean isChecked) {
        SharedPreferences sp = context.getSharedPreferences(MIUI, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putBoolean(MIUI, isMIUI);
        editor.putBoolean("isChecked", isChecked);
        editor.commit();
    }

    public static boolean getMIUI(Context context) {
        SharedPreferences sp = context.getSharedPreferences(MIUI, 0);
        boolean isMIUI = sp.getBoolean(MIUI, false);
        return isMIUI;
    }

    public static boolean getMIUIChecked(Context context) {
        SharedPreferences sp = context.getSharedPreferences(MIUI, 0);
        boolean isChecked = sp.getBoolean("isChecked", false);
        return isChecked;
    }


    public static void saveLocalOrder(Context context, LocalOrderEntity localOrderEntity) {
        String soeStr = JacksonUtil.getInstance().writeValueAsString(localOrderEntity);
        saveLocalOrder(context, soeStr);
    }

    public static LocalOrderEntity getLocalOrderEntity(Context context) {
        LocalOrderEntity localOrderEntity = null;
        String str = getLocalOrder(context);
        if (!StringUtil.isEmpty(str)){
            localOrderEntity = JacksonUtil.getInstance().readValue(str,LocalOrderEntity.class);
        }
        return localOrderEntity;
    }

    public static void saveLocalOrder(Context context, String str) {
        SharedPreferences sp = context.getSharedPreferences(LOCAL_ORDER, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString("str", str);
        editor.commit();
    }

    public static String getLocalOrder(Context context) {
        SharedPreferences sp = context.getSharedPreferences(LOCAL_ORDER, 0);
        String str = sp.getString("str", "");
        if (StringUtil.isEmpty(str)) {
            str = "";
        }
        return str;
    }
}